#include "particle.h"

particle::particle()
{

}

particle::particle(GLuint ttex, float dd, float tt, float xx, float yy, float ww, float hh, float aa, float dtt, float dxx, float dyy, float dww, float dhh, float daa, float rr, float gg, float bb, float drr, float dgg, float dbb)
{
    tex = ttex;
    d = dd;
    x = xx;
    y = yy;
    w = ww;
    h = hh;
    a = aa;
    t = tt;
    r = rr;
    g = gg;
    b = bb;

    dx = dxx;
    dy = dyy;
    dw = dww;
    dh = dhh;
    da = daa;
    dt = dtt;
    dr = drr;
    dg = dgg;
    db = dbb;
}

particle::~particle()
{

}

void particle::draw(ptrContainer & dcontainer)
{
    glPushMatrix();
    if (a == 0)
    {
        glTranslatef(x,y,0);
    } else {
        glTranslatef(x+(w/2),y+(h/2),0);
        glRotatef(a,0,0,1);
        glTranslatef(-(w/2),-(h/2),0);
    }
    
    glBindTexture(GL_TEXTURE_2D, tex);
    glColor4f(1,1,1,1-t);
    glBegin(GL_QUADS);
    glTexCoord2i(0,0); //Texture coord
    glVertex3f(0,0,0); //Point coord

    glTexCoord2i(1,0);
    glVertex3f(w,0,0);
    
    glTexCoord2i(1,1);
    glVertex3f(w,h,0);

    glTexCoord2i(0,1);
    glVertex3f(0,h,0);
    glEnd();
    glColor4f(1,1,1,1);
    glPopMatrix();
    glLoadIdentity();
}

void particle::update(double prog)
{
    float per = prog;
    a += da * per;
    x += dx * per;
    y += dy * per;
    w += dw * per;
    h += dh * per;
    t += dt * per;
    d -= per;
    r += dr * per;
    g += dg * per;
    b += db * per;
}
